﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TeamBuy.AccessWebUI.Account
{
    public partial class Order : System.Web.UI.Page
    {
        //public static string query;
        public bool isSetStatus = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Show"] != null && Request.QueryString["Show"] != "")
            {
                if (Convert.ToString(Request.QueryString["Show"]) == "All")
                {
                    ltlAllStyle.Text = "class='current'";
                    ltlNotPaiedStyle.Text = "";
                    ltlPaiedStyle.Text = "";
                    adsOrder.SelectCommand = "SELECT * FROM [vw_OrderInfo] WHERE UserID = " + Session["UserID"] + " ORDER BY [OrderID] DESC";

                }
                else if (Convert.ToString(Request.QueryString["Show"]) == "NotPaied")
                {
                    ltlAllStyle.Text = "";
                    ltlNotPaiedStyle.Text = "class='current'";
                    ltlPaiedStyle.Text = "";
                    adsOrder.SelectCommand = "SELECT * FROM [vw_OrderInfo] WHERE UserID = " + Session["UserID"] + " AND OrderStatus<>1 ORDER BY [OrderID] DESC";

                }
                else if (Convert.ToString(Request.QueryString["Show"]) == "Paied")
                {
                    ltlAllStyle.Text = "";
                    ltlNotPaiedStyle.Text = "";
                    ltlPaiedStyle.Text = "class='current'";
                    adsOrder.SelectCommand = "SELECT * FROM [vw_OrderInfo] WHERE UserID = " + Session["UserID"] + " AND OrderStatus=1 ORDER BY [OrderID] DESC";

                }
                else
                {
                    ltlAllStyle.Text = "class='current'";
                    ltlNotPaiedStyle.Text = "";
                    ltlPaiedStyle.Text = "";
                    adsOrder.SelectCommand = "SELECT * FROM [vw_OrderInfo] WHERE UserID = " + Session["UserID"] + " ORDER BY [OrderID] DESC";
                }
            }
            else
            {
                ltlAllStyle.Text = "class='current'";
                ltlNotPaiedStyle.Text = "";
                ltlPaiedStyle.Text = "";
                adsOrder.SelectCommand = "SELECT * FROM [vw_OrderInfo] WHERE UserID = " + Session["UserID"] + " ORDER BY [OrderID] DESC";
            }
        }

        protected void lbtnAll_Click(object sender, EventArgs e)
        {
            Response.Redirect("Order.aspx?Show=All");
            //ltlAllStyle.Text = "class='current'";
            //ltlNotPaiedStyle.Text = "";
            //ltlPaiedStyle.Text = "";
            //adsOrder.SelectCommand = "SELECT * FROM [vw_OrderInfo] WHERE UserID = " + Session["UserID"] + " ORDER BY [OrderID] DESC";
            //query = adsOrder.SelectCommand;
        }

        protected void lbtnNotPaied_Click(object sender, EventArgs e)
        {
            Response.Redirect("Order.aspx?Show=NotPaied");

            //ltlNotPaiedStyle.Text = "class='current'";
            //ltlPaiedStyle.Text = "";
            //adsOrder.SelectCommand = "SELECT * FROM [vw_OrderInfo] WHERE UserID = " + Session["UserID"] + " AND OrderStatus<>1 ORDER BY [OrderID] DESC";
            //query = adsOrder.SelectCommand;
        }

        protected void lbtnPaied_Click(object sender, EventArgs e)
        {
            Response.Redirect("Order.aspx?Show=Paied");
            //ltlAllStyle.Text = "";
            //ltlNotPaiedStyle.Text = "";
            //ltlPaiedStyle.Text = "class='current'";
            //adsOrder.SelectCommand = "SELECT * FROM [vw_OrderInfo] WHERE UserID = " + Session["UserID"] + " AND OrderStatus=1 ORDER BY [OrderID] DESC";
            //query = adsOrder.SelectCommand;
        }

        public string SetStatus(int orderID, int oldStatus, int currentStatus, string returnString)
        {
            TeamBuy.AccessService.TeamBuyOrderService setOrderStatus = new AccessService.TeamBuyOrderService();
            setOrderStatus.SetOrderCurrentStatus(orderID, oldStatus, currentStatus);
            lvOrder.Items.Clear();
            if (isSetStatus == false)
            {
                isSetStatus = true;
            }
            return returnString;
        }

        protected void lvOrder_DataBound(object sender, EventArgs e)
        {
            if (isSetStatus == true)
            {
                isSetStatus = false;
                lvOrder.DataBind();
            }
        }
    }
}